import request from '@/api/request'

/**
 * 分区管理API接口
 */
export const zoneApi = {
  /**
   * 分页查询分区列表
   */
  getZoneList: (params: any) => {
    return request.get('/region/zones', { params })
  },

  /**
   * 根据ID查询分区详情
   */
  getZoneDetail: (id: number) => {
    return request.get(`/region/zones/${id}`)
  },

  /**
   * 创建新分区
   */
  createZone: (data: any) => {
    return request.post('/region/zones', data)
  },

  /**
   * 更新分区信息
   */
  updateZone: (id: number, data: any) => {
    return request.put(`/region/zones/${id}`, data)
  },

  /**
   * 删除分区
   */
  deleteZone: (id: number) => {
    return request.delete(`/region/zones/${id}`)
  },

  /**
   * 查询社区分区列表
   */
  getZonesByCommunity: (communityId: number) => {
    return request.get(`/region/zones/community/${communityId}`)
  },

  /**
   * 查询物业公司分区列表
   */
  getZonesByPropertyCompany: (propertyCompanyId: number) => {
    return request.get(`/region/zones/property-company/${propertyCompanyId}`)
  },

  /**
   * 检查分区编码是否存在
   */
  checkZoneCode: (params: any) => {
    return request.get('/region/zones/check-code', { params })
  }
}

/**
 * 分区绘图API接口
 */
export const zoneDrawingApi = {
  /**
   * 保存分区绘图数据
   */
  saveZoneDrawing: (data: any) => {
    return request.post('/region/zone-drawings', data)
  },

  /**
   * 更新分区绘图数据
   */
  updateZoneDrawing: (id: number, data: any) => {
    return request.put(`/region/zone-drawings/${id}`, data)
  },

  /**
   * 删除分区绘图数据
   */
  deleteZoneDrawing: (id: number) => {
    return request.delete(`/region/zone-drawings/${id}`)
  },

  /**
   * 获取社区绘图数据
   */
  getCommunityDrawingData: (communityId: number) => {
    return request.get(`/region/zone-drawings/community/${communityId}`)
  },

  /**
   * 导入绘图数据
   */
  importDrawingData: (data: any) => {
    return request.post('/region/zone-drawings/import', data)
  },

  /**
   * 导出绘图数据
   */
  exportDrawingData: (params: any) => {
    return request.get('/region/zone-drawings/export', { params })
  }
}

/**
 * 分区协作API接口
 */
export const zoneCollaborationApi = {
  /**
   * 加入协作会话
   */
  joinCollaboration: (data: any) => {
    return request.post('/region/zone-collaboration/join', data)
  },

  /**
   * 离开协作会话
   */
  leaveCollaboration: (data: any) => {
    return request.post('/region/zone-collaboration/leave', data)
  },

  /**
   * 获取协作会话列表
   */
  getCollaborationSessions: () => {
    return request.get('/region/zone-collaboration/sessions')
  },

  /**
   * 锁定分区编辑
   */
  lockZone: (data: any) => {
    return request.post('/region/zone-collaboration/lock', data)
  },

  /**
   * 解锁分区编辑
   */
  unlockZone: (data: any) => {
    return request.post('/region/zone-collaboration/unlock', data)
  },

  /**
   * 获取在线用户列表
   */
  getOnlineUsers: () => {
    return request.get('/region/zone-collaboration/online-users')
  },

  /**
   * 发送聊天消息
   */
  sendChatMessage: (data: any) => {
    return request.post('/region/zone-collaboration/chat', data)
  },

  /**
   * 获取聊天历史
   */
  getChatHistory: (params: any) => {
    return request.get('/region/zone-collaboration/chat-history', { params })
  }
}

/**
 * 分区管理综合API接口
 */
export const zoneManagementApi = {
  /**
   * 获取分区管理页面初始数据
   */
  getInitialData: (communityId: number) => {
    return request.get(`/region/zone-management/initial-data/${communityId}`)
  },

  /**
   * 保存分区管理数据
   */
  saveZoneData: (data: any) => {
    return request.post('/region/zone-management/save', data)
  },

  /**
   * 判断社区进入状态
   */
  determineCommunityEntryState: (communityId: number) => {
    return request.get(`/region/zone-management/entry-state/${communityId}`)
  },

  /**
   * 更新分区基本信息
   */
  updateZoneInfo: (zoneId: number, data: any) => {
    return request.put(`/region/zone-management/info/${zoneId}`, data)
  },

  /**
   * 更新分区绘图数据
   */
  updateZoneDrawing: (zoneId: number, data: any) => {
    return request.put(`/region/zone-management/drawing/${zoneId}`, data)
  }
}

/**
 * 分区统计API接口
 */
export const zoneStatisticsApi = {
  /**
   * 生成分区统计数据
   */
  generateZoneStatistics: (zoneId: number) => {
    return request.post(`/region/zone-statistics/zone/${zoneId}/generate`)
  },

  /**
   * 获取分区统计数据
   */
  getZoneStatistics: (zoneId: number) => {
    return request.get(`/region/zone-statistics/zone/${zoneId}`)
  },

  /**
   * 获取分区统计趋势
   */
  getZoneStatisticsTrend: (zoneId: number, params: any) => {
    return request.get(`/region/zone-statistics/zone/${zoneId}/trend`, { params })
  },

  /**
   * 获取社区分区统计对比
   */
  getCommunityStatisticsComparison: (communityId: number) => {
    return request.get(`/region/zone-statistics/community/${communityId}/comparison`)
  },

  /**
   * 获取物业公司分区统计排名
   */
  getPropertyCompanyStatisticsRanking: (propertyCompanyId: number) => {
    return request.get(`/region/zone-statistics/property-company/${propertyCompanyId}/ranking`)
  },

  /**
   * 获取分区综合统计报告
   */
  getZoneComprehensiveReport: (zoneId: number) => {
    return request.get(`/region/zone-statistics/zone/${zoneId}/comprehensive-report`)
  },

  /**
   * 批量生成分区统计数据
   */
  batchGenerateZoneStatistics: (communityId: number) => {
    return request.post(`/region/zone-statistics/community/${communityId}/batch-generate`)
  },

  /**
   * 获取分区实时统计数据
   */
  getZoneRealTimeStatistics: (zoneId: number) => {
    return request.get(`/region/zone-statistics/zone/${zoneId}/real-time`)
  },

  /**
   * 导出分区统计数据
   */
  exportZoneStatistics: (zoneId: number, params: any) => {
    return request.get(`/region/zone-statistics/zone/${zoneId}/export`, { params })
  },

  /**
   * 获取分区统计概览
   */
  getZoneStatisticsOverview: (zoneId: number) => {
    return request.get(`/region/zone-statistics/zone/${zoneId}/overview`)
  },

  /**
   * 清理历史统计数据
   */
  cleanupHistoricalStatistics: () => {
    return request.delete('/region/zone-statistics/cleanup')
  }
}
